package com.crm.controller;

import com.crm.dto.ClueDto;
import com.crm.dto.ClueQueryPagePramDto;
import com.crm.dto.GainDto;
import com.crm.dto.IsFalseDto;
import com.crm.pojo.BusinessRecord;
import com.crm.pojo.Clue;
import com.crm.result.PageResult;
import com.crm.result.ResponseResult;
import com.crm.result.Result;
import com.crm.service.ClueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clues")
@Slf4j
@Api(tags = "线索管理相关接口")
public class ClueController {
    @Autowired
    private ClueService clueService;

    /**
     * 线索分页查询
     */
    @ApiOperation("线索分页查询")
    @GetMapping("/clue/list")
    public Result queryPageClue(ClueQueryPagePramDto dto) {
        log.info("线索分页查询参数{}", dto);
        PageResult result = clueService.queryPageClue(dto);
        return Result.commonSuccess(result);
    }

    /**
     * 新增线索
     */
    @PostMapping("/clue")
    public ResponseResult addClue(@RequestBody ClueDto dto) {
        log.info("新增线索参数{}", dto);
        clueService.addClue(dto);
        return ResponseResult.success();

    }

    /**
     * 根据线索id查询基本信息
     */
    @GetMapping("/clue/{id}")
    public Result queryById(@PathVariable Long id) {
        log.info("根据id{}查询线索基本信息", id);
        Clue result = clueService.queryById(id);
        return Result.success(result);

    }

    /**
     * 分页查询线索池信息
     */
    @GetMapping("/clue/pool")
    public Result queryCluePool(ClueQueryPagePramDto dto) {
        log.info("分页查询线索池信息{}", dto);
        PageResult result = clueService.queryPagePool(dto);
        return Result.commonSuccess(result);
    }

    /**
     * |查询跟进记录信息
     */
    @GetMapping("/record/list")
    public Result queryRecord(Long clueId) {
        log.info("根据线索id查询{}跟进记录", clueId);
        PageResult result = clueService.queryRecord(clueId);
        return Result.commonSuccess(result);
    }

    /**
     * 添加线索跟进信息
     */
    @PostMapping("/record")
    public ResponseResult addRecord(@RequestBody BusinessRecord record) {
        log.info("添加线索跟进");
        //clueService.addRecord(record);
        return ResponseResult.success();

    }

    /**
     * 从线索池中捞取
     */
    @PutMapping("/clue/gain")
    public ResponseResult gain(@RequestBody GainDto gain) {
        log.info("捞取的参数{}", gain);
        clueService.gainClue(gain);
        return ResponseResult.success();
    }

    /**
     * 伪线索
     */
    @PutMapping("/clue/false/{id}")
    public ResponseResult IsFalse(@PathVariable Long id, @RequestBody IsFalseDto dto) {
        clueService.isFalse(id, dto);
        return ResponseResult.success();
    }


}
